package com.aliyun.oss.UserService.impl;

import com.aliyun.oss.UserMapper.OrderDetailMapper;
import com.aliyun.oss.UserService.OrderDetailService;
import com.aliyun.oss.pojo.Entity.OrderDetail;
import com.aliyun.oss.pojo.Entity.ShoppingCart;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements OrderDetailService {
    @Override
    public void insertBatch(Long id, List<ShoppingCart> list) {
        for (ShoppingCart shoppingCart : list) {
            OrderDetail orderDetail = new OrderDetail();
            orderDetail.setOrderId(id);
            if(shoppingCart.getDishId() != null)
            orderDetail.setDishId(shoppingCart.getDishId().longValue());
            if(shoppingCart.getSetmealId() != null)
            orderDetail.setSetmealId(shoppingCart.getSetmealId().longValue());
            orderDetail.setName(shoppingCart.getName());
            orderDetail.setImage(shoppingCart.getImage());
            orderDetail.setDishFlavor(shoppingCart.getDishFlavor());
            orderDetail.setNumber(shoppingCart.getNumber());
            orderDetail.setAmount(shoppingCart.getAmount());
            this.baseMapper.insert(orderDetail);
        }

    }
}
